package com.example.base.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object RetrofitUtils {

    val client by lazy {
        OkHttpClient.Builder()
            .readTimeout(30,TimeUnit.SECONDS)
            .writeTimeout(30,TimeUnit.SECONDS)
            .connectTimeout(30,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                val token = SPUtils.getInstance().getString("token")
                val builder = it.request().newBuilder()
                builder.addHeader("token",token)
                    .addHeader("accessId","873b63cb86974f10b8746fa07e2bb014")
                return@addInterceptor it.proceed(builder.build())
            }
            .build()
    }

    val getRetrofit by lazy {
        Retrofit.Builder()
            .baseUrl("http://10.161.9.80:2209/")
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
}